<!--
 * @Description: 
 * @Author: xuzp4
 * @Date: 2022-03-22 12:57:05
 * @LastEditors: xuzp4
 * @LastEditTime: 2022-03-22 22:43:13
 * @FilePath: \visitor_management\src\components\Pagination.vue
-->
<template>
  <div :class="{ hidden: hidden }" class="pagination-container">
    <el-pagination
      :background="background"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: "Pagination",
  props: {
    total: {
      required: true,
      type: Number,
    },
    page: {
      type: Number,
      default: 1,
    },
    limit: {
      type: Number,
      default: 20,
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50];
      },
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper",
    },
    background: {
      type: Boolean,
      default: true,
    },
    hidden: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    currentPage: {
      get() {
        return this.page;
      },
      set(val) {
        this.$emit("update:page", val);
      },
    },
    pageSize: {
      get() {
        return this.limit;
      },
      set(val) {
        this.$emit("update:limit", val);
      },
    },
  },
  methods: {
    handleSizeChange(val) {
      if ((this.currentPage - 1) * val <= this.total) {
        this.$emit("pagination", { page: this.currentPage, limit: val });
      }
    },
    handleCurrentChange(val) {
      if ((this.currentPage - 1) * this.pageSize <= this.total) {
        this.$emit("pagination", { page: val, limit: this.pageSize });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.pagination-container {
  padding: 17px 16px 40px;
  height: 89px;
}
.pagination-container.hidden {
  display: none;
}
.pagingStyle {
  float: right;
}
.el-pagination {
  float: right;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #d4eef4 !important;
  color: #383838;
}
.el-pagination.is-background .btn-next, .el-pagination.is-background .btn-prev, .el-pagination.is-background .el-pager li {
     background-color: #d4eef4 !important;
    color:#383838;
}
</style>
